import { Application } from 'egg';
import {
    indexRule,
    couponRule,
    categoryByIdRule
} from '../validate/xxm/index'

/**
 * 小程序路由
 */
export default (app: Application) => {
    const { header } = app.middleware;
    // const { jwt } = app;

    return {
        'xxm.home': {
          method: 'GET',
          path: '/xxm/home/index',
          options: {
            tags: ['xxm/index'],
            description: '首页',
            handler: app.controller.xxm.home.index,
            middlewares: [header()],
            validate: indexRule,
          },
        },
        'xxm.category.list': {
          method: 'GET',
          path: '/xxm/category/list',
          options: {
            tags: ['xxm/category/list'],
            description: '分类',
            handler: app.controller.goods.category.listAll,
            middlewares: [header()],
            validate: indexRule,
          },
      },
      'xxm.category.goods.id': {
        method: 'GET',
        path: '/xxm/category/goods/:id',
        options: {
          tags: ['xxm/category/goods/id'],
          description: '分类-商品',
          handler: app.controller.goods.main.goodsByCategoryId,
          middlewares: [header()],
          validate: categoryByIdRule,
        },
      },
      'xxm.market.coupon': {
        method: 'GET',
        path: '/xxm/coupon/list',
        options: {
          tags: ['xxm/coupon/list'],
          description: '优惠券列表',
          handler: app.controller.marketing.coupon.userCoupon,
          middlewares: [header()],
          validate: couponRule,
        },
      },

    };
};
